# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=pngquant
pkgver=3.0.3
pkgrel=0
_libimagequant=4.2.2
pkgdesc="Lossy PNG compressor"
url="https://pngquant.org/"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	cargo
	cargo-auditable
	lcms2-dev
	libpng-dev
	"
subpackages="$pkgname-doc"
source="https://github.com/kornelski/pngquant/archive/$pkgver/pngquant-$pkgver.tar.gz
	libimagequant-$_libimagequant.tar.gz::https://github.com/ImageOptim/libimagequant/archive/refs/tags/$_libimagequant.tar.gz
	Cargo.lock
	"
options="!check" # seems to not have any runnable anymore

prepare() {
	default_prepare
	rmdir lib
	ln -sfv "$srcdir"/libimagequant-$_libimagequant lib
	ln -sfv "$srcdir"/Cargo.lock Cargo.lock
	cargo fetch --target="$CTARGET" --locked
}

build() {
	# 20% faster than =s/=2
	export CARGO_PROFILE_RELEASE_OPT_LEVEL=3
	cargo auditable build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/pngquant -t "$pkgdir"/usr/bin/
	install -Dm644 pngquant.1 -t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
8d4b290e4b9fbd5061c28d9521f514c36e091d26d27b72b27d06349b8948582baddb4e81a0be653eca9ebbacb1b8722db4cd5d35ed0d19f96f610b0de4ccb0bc  pngquant-3.0.3.tar.gz
31bd79024abc1fd884461f8f422d6eac1f5786ce347ac3c517e9cb66f289ad1ace0e3a25c55c7b7384badb2545174871464d60f1238ed2deb1f521d5f3ede96b  libimagequant-4.2.2.tar.gz
84779c482ef0b40d6f11776d81f2e41dd37e0e4d083d930de1beb07f487b74a69348862021d43d56d8daf7b5cfefed31f425d9f74f5177d38952a84fb94c19ba  Cargo.lock
"
